import { AxiosPromise } from "axios";
import request from "@/utils/request";
import { type QueryParams, ListResult, CraftItem, DelResult } from "./types";

// 获取工艺列表
export const getCraftList = (
  params: QueryParams
): AxiosPromise<ListResult<CraftItem>> => {
  return request({
    method: "get",
    url: "/api/craft/index",
    params,
  });
};

// 添加工艺
export const addCraft = (data: any): AxiosPromise<DelResult> => {
  return request({
    method: "post",
    url: "/api/craft/add",
    data,
  });
};

// 编辑工艺
export const editCraft = (id: number, data: any): AxiosPromise<DelResult> => {
  return request({
    method: "post",
    url: `/api/craft/edit/id/${id}`,
    data,
  });
};

// 切换默认工艺
export const setDefaultCraft = (
  id: number,
  params: any
): AxiosPromise<DelResult> => {
  return request({
    method: "get",
    url: `/api/craft/convertDefault/id/${id}`,
    params,
  });
};

// 删除工艺 api/craft/del/ids/xxx,xxx
export const delCraft = (ids: string, params: any): AxiosPromise<DelResult> => {
  return request({
    method: "get",
    url: `/api/craft/del/ids/${ids}`,
    params,
  });
};

// 获取默认工艺
export const getDefaultCraft = (params: any) => {
  return request({
    method: "get",
    url: `/api/craft/findDefault`,
    params,
  });
};
